package urldata

import (
	"encoding/json"
	"github.com/kataras/iris/context"
)
type  Sign struct{
	Id int `json:"id"`
	Token string `json:"token"`
}
type  GetData struct{
	Data json.RawMessage `json:"data"`
	Timestamp string `json:"timestamp"`
	Sign string `json:"sign"`

}
type  AuthData struct{
	Uid int `json:"uid"`
	Token string `json:"token"`
}
func MyUnmarshal(ctx context.Context,t interface{}) error  {
	tmp:=GetData{}
	err:=ctx.ReadJSON(&tmp)
	if err!=nil {
		return err
	}
	err=json.Unmarshal(tmp.Data,&t)
	return err
}

func GetBean(mytype interface{})  {
	return
}
const (
	Http_Success=200
	Http_NeedAuth=201
	Http_SAVE=202
	Http_Fail=404
	Bean="bean"
	Uid="uid"
)
const (
	MSG="msg"
	JSON="json"
	REDIRECT="red"
)

type SendData struct {
	Code int `json:"code"`
	Summary string `json:"summary"`
	Data interface{} `json:"data"`
	Sort string `json:"sort,omitempty"`
	Url string `json:"url,omitempty"`
}
type SendInit interface {
	Init(code int,summary string,data interface{})
}

func (sendData *SendData) Init (code int,summary string,data interface{}) {
	sendData.Code=code
	sendData.Summary=summary
	sendData.Data=data
}
func RetSuccess(data interface{})SendData {
	return SendData{Code:Http_Success,Summary:"ok",Data:data }
}
func RetSuccessMsg(data interface{})SendData {
	return SendData{Code:Http_Success,Summary:"提示",Data:data,Sort:MSG }
}
func RetSuccessUrl(data interface{},url string)SendData {
	return SendData{Code:Http_Success,Summary:"ok",Data:data,Sort:MSG ,Url:url}
}
func RetFail(data interface{})SendData {
	return SendData{Code:Http_Fail,Summary:"fail",Data:data }
}
func RetNeedAuth(data interface{})SendData {
	return SendData{Code:Http_NeedAuth,Summary:"need auth",Data:data }
}